package com.sbpm.crmbpm.server.dao;

import com.sbpm.crmbpm.shared.TransferEntity;
import com.sbpm.crmbpm.shared.data.TaskInfo;
import com.sbpm.crmbpm.shared.data.TransferInfo;
import org.kie.api.task.model.TaskSummary;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class ObjectConverter
{
    public TaskInfo convertTask( TaskSummary taskSummary )
    {
        TaskInfo task = new TaskInfo();
        task.setActivationTime(taskSummary.getActivationTime());
        task.setActualOwner(taskSummary.getActualOwnerId());
        task.setCreatedBy(taskSummary.getCreatedById());
        task.setCreatedById(taskSummary.getCreatedById());
        task.setCreatedOn(taskSummary.getCreatedOn());
        task.setDeploymentId(taskSummary.getDeploymentId());
        task.setDescription(taskSummary.getDescription());
        task.setExpirationTime(taskSummary.getExpirationTime());
        task.setGetProcessSessionId(taskSummary.getProcessSessionId());
        task.setId(taskSummary.getId());
        task.setIsQuickTaskSummary(taskSummary.isQuickTaskSummary());
        task.setIsSkipable(taskSummary.isSkipable());
        task.setName(taskSummary.getName());
        task.setParentId(taskSummary.getParentId());
        task.setPriority(taskSummary.getPriority());
        task.setProcessId(taskSummary.getProcessId());
        task.setProcessInstanceId(taskSummary.getProcessInstanceId());
        task.setStatus(taskSummary.getStatus().toString());
        task.setStatusId(taskSummary.getStatusId());
        task.setSubject(taskSummary.getSubject());

        return task;
    }

    public List<TaskInfo> convertTaskList( List<TaskSummary> list )
    {
        List<TaskInfo> tasks = new ArrayList<TaskInfo>();
        for (TaskSummary taskSummary : list)
        {
            tasks.add( convertTask( taskSummary ) );
        }
        return tasks;
    }

    public TransferInfo convertTransfer( TransferEntity transferEntity )
    {
        TransferInfo info = new TransferInfo();
        info.setReceiver( transferEntity.getReceiver() );
        info.setSum( transferEntity.getSum() );
        info.setName( transferEntity.getName() );
        info.setId( transferEntity.getId() );
        info.setProcessInstanceId( transferEntity.getProcessInstanceId() );
        return info;
    }

    public TransferEntity convertTransfer( TransferInfo info )
    {
        TransferEntity entity = new TransferEntity();
        entity.setProcessInstanceId( info.getProcessInstanceId() );
        entity.setReceiver( info.getReceiver() );
        entity.setSum( info.getSum() );
        entity.setId( info.getId() );
        entity.setName( info.getName() );
        return entity;
    }
}
